package com.rayo.accesscontrollercopy.model.db.dao;


import com.rayo.accesscontrollercopy.model.db.DbHelp;
import com.rayo.accesscontrollercopy.model.db.bean.SystemData;

import java.util.List;

/**
 * Created by yanghaojie on 16/7/13.
 */
public class SystemDataImpl implements SystemDataDao {
    @Override
    public List<SystemData> findAll() {
        return DbHelp.getQueryAll(SystemData.class);
    }

    @Override
    public SystemData findFirst() {
        List<SystemData> list = findAll();
        if (null == list || 0 == list.size())
            return new SystemData();
        else
            return list.get(0);
    }

    @Override
    public void addSystem(SystemData systemData) {
        DbHelp.insert(systemData);
    }

    @Override
    public void updateSystem(SystemData systemData) {
        List<SystemData> list = findAll();
        if (null == list || 0 == list.size())
            DbHelp.insert(systemData);
        else
            DbHelp.update(systemData);
    }

    @Override
    public void deleteAll() {
        DbHelp.deleteAll(SystemData.class);
    }
}
